import axios from "../../utils/request";

const baseURL = '/wordCheck'
const state = {
  wordCheckData:{}
}

//方法参考地址
//https://www.jb51.net/article/261401.htm
const mutations = {

//保存列表信息
  setWordCheckData: (state, data) => {
    state.wordCheckData = data
  },

}
const actions = {

  //获取列表数据
  getListPageData: function ({commit}, params) {
    // console.log('params ' +JSON.stringify(params))
    return new Promise((resolve, reject) => {
      // const params = {page:1,pageSize:1}; // 参数
      axios.get(baseURL+'/listPage', {params:params}).then((res) => {
        // console.log('find ' +JSON.stringify(res))
        resolve(res.data)
      }).catch((error) => {
        reject(error)
      })

    }).catch(error=>{
      console.log(error)
    })

  },

  /**
   * 查询考试结果和结果明细
   * @param commit
   * @param params
   * @returns {Promise<unknown>}
   */
  findDetailToStudent: function ({commit}, params) {
    // console.log('params ' +JSON.stringify(params))
    return new Promise((resolve, reject) => {
      axios.get(baseURL+'/findDetailToStudent', {params:params}).then((res) => {
        // console.log('find ' +JSON.stringify(res.data))
        commit("setWordCheckData", res.data)
        resolve(res.data)
      }).catch((error) => {
        reject(error)
      })

    }).catch(error=>{
      console.log(error)
    })

  },

  /**
   * 保存或更新数据
   * @param commit
   * @param params
   * @returns {Promise<unknown>}
   */
  saveWordCheckData: function ({commit}, from) {
    return new Promise((resolve, reject) => {
      // console.log('from ' +JSON.stringify(from))
      axios.post(baseURL+'/saveWordCheckData', from).then((res) => {
        resolve(res)
      }).catch((error) => {
        reject(error)
      })

    }).catch(error=>{
      console.log(error)
    })

  },

  /**
   * 删除数据
   * @param commit
   * @param params
   * @returns {Promise<unknown>}
   */
  deleteWordCheck: function ({commit}, id) {
    return new Promise((resolve, reject) => {
      axios.delete(baseURL+'/deleteByIds?ids='+id).then((res) => {
        resolve(res)
      }).catch((error) => {
        reject(error)
      })
    }).catch(error=>{
      console.log(error)
    })

  },


}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
